//
// Created by xming-kaede on 2024/7/4.
//

#ifndef GAME_PROCESS_H
#define GAME_PROCESS_H

#include <netdata.h>
#include "../src/ui/element/Map.h"

enum RoomStatus {
    UNAVAILABLE,
    AVAILABLE,
    BUSY,
};
typedef struct{
    char* Ip;
    int OnlinePlayerCount;
    char* Info;
    int Status;
}RemoteRoomInfo;
typedef struct{
    int Status;
    int OnlinePlayerCount;
    char* Info;
    char** PlayerIps;
}Room;
struct Player{
    int id;
    int x,y;
    int direction;
    int health;
    int baseHealth;
    int accumulateTime;
    int ammunition;
} ;
struct PlayerStatus {
    int tick;
    Player playerData;
};
struct Projectile {
    int level;
    int health;
    int x,y;
    int direction;
    int shooter;
    int shootTick;
};
struct ProjectileLevelData {
    int durability;
    int damage;
    int speed;
    int consume;
    IMAGE img;
};
extern Room LocalRoom;
extern ProjectileLevelData ProjectileModel[5];
int GetTick();
void SetTick(int tick);
int GetMoveX(int direction);
int GetMoveY(int direction);
int GetShootX(Player &player);
int GetShootY(Player &player);
int GetLocalPlayerIdByXY(Player *pls, int x, int y);
PixelXY GetPlayerBaseXY(Map &m,int id);
bool IsPlayerInBase(Map &m,Player* pls,int id);
//client
extern bool IsHost;
extern bool ClientPlayerList[4];
extern int myId;
extern bool GameStarted;
bool JoinRoom(char* serverAddrStr);
void SetMyId(int id);
void UpdateClientPlayerList(const char *list);
//player
void PlayerStartGame(const bool *playerList);
void PlayerGameOver();
void TickExecuteServerPack();
//server
bool StartRoom(char* RoomInfo);
void CloseRoom();
void GenerateLocalRoomInfo(char *buffer);
bool IsAllPlayerReadyToStart();
//game server
void ServerStartGame();
void ExecutePlayerPackage(GamePack pack,char *buffer);
void ServerStopGame();
//room list manager
void AddRemoteRoom(char* RoomInfo, char* Ip);
void ClearRoomList();
void StopFindRoom();
//projectile
int GetProjectileDurability(int level);
int GetProjectileDamage(int level);
int GetProjectileSpeed(int level);
int GetProjectileConsume(int level);
IMAGE* GetProjectileImage(int level);
#endif //GAME_PROCESS_H
